import { UPLOAD_DIR } from '../config/oss'
import { API_URL } from '@/config/api'
import useUserStore from '@/store/user'

// 上传文件
export const upload = (filePath) => {
  const usetStore = useUserStore()

  return new Promise((resolve, reject) => {
    uni.uploadFile({
      url: `${API_URL}/n5/image/upload`,
      filePath,
      name: 'file',
      header: { token: usetStore.token },
      formData: { route: UPLOAD_DIR() },
      success: res => {
        const data = JSON.parse(res.data)
        resolve(data.data)
      },
      fail: err => reject(err)
    })
  })
}
